#!/bin/bash

# create openvpn image
docker build -t apollozhu/openvpn:v1 .

export OVPN_DATA="ovpn-data"

# Initialize the $OVPN_DATA container that will hold the configuration files and certificates
docker volume create --name $OVPN_DATA
docker run -v $OVPN_DATA:/etc/openvpn --rm apollozhu/openvpn:v1 ovpn_genconfig -D -u udp://vpn.wx-rdc.top
docker run -v $OVPN_DATA:/etc/openvpn --rm -it apollozhu/openvpn:v1 ovpn_initpki

# Generate a client certificate without a passphrase
docker run -v $OVPN_DATA:/etc/openvpn --rm -it apollozhu/openvpn:v1 easyrsa build-client-full client01 nopass

# Retrieve the client configuration with embedded certificates
docker run -v $OVPN_DATA:/etc/openvpn --rm apollozhu/openvpn:v1 ovpn_getclient client01 > client01.ovpn

# Start OpenVPN server process
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN apollozhu/openvpn:v1


